Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better formatting for sparse arrays #20379

Merged
merged 5 commits into from
Jan 27, 2023

Conversation

aslushnikov
Copy link
Collaborator

@aslushnikov aslushnikov commented Jan 25, 2023

Right now arrays preview yields all array elements. In case
of a sparse array with a single element on index 10000000,
this results in a large string that OOM Node.js.

This patch changes pretty-printing. For example:

// Given this array
const a = [];
a[10] = 1;
// Before this patch, pretty printing will yield:
"[,,,,,,,,1]"
// With this patch, pretty printing yields:
"[empty x 9, 1]"

The new array pretty-printing is equal to what Chrome DevTools
do to render sparse arrays.

Fixes #20347

Right now arrays preview yields all array elements. In case
of a sparse array with a single element on index 10000000,
this results in a large string that OOM Node.js.

This patch changes pretty-printing. For example:

```ts
// Given this array
const a = [];
a[10] = 1;
// Before this patch, pretty printing will yield:
"[,,,,,,,,1]"
// With this patch, pretty printing yields:
"[<9 empty items>,1]"
```

The new array pretty-printing is equal to what Node.js CLI
does to render sparse arrays.

Fixes microsoft#20347
@aslushnikov aslushnikov merged commit 9ca9b08 into microsoft:main Jan 27, 2023
@aslushnikov aslushnikov deleted the format-sparse-arrays branch January 27, 2023 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]
3 participants